package com.ruoyi.web.controller.mall;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserCouponsHistory;
import com.ruoyi.system.service.IUserCouponsHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户优惠券历史Controller
 * 
 * @author ruoyi
 * @date 2024-03-22
 */
@Controller
@RequestMapping("/mall/userCouponsHistory")
public class UserCouponsHistoryController extends BaseController
{
    private String prefix = "mall/userCouponsHistory";

    @Autowired
    private IUserCouponsHistoryService userCouponsHistoryService;

    @RequiresPermissions("mall:userCouponsHistory:view")
    @GetMapping()
    public String userCouponsHistory()
    {
        return prefix + "/userCouponsHistory";
    }

    /**
     * 查询用户优惠券历史列表
     */
    @RequiresPermissions("mall:userCouponsHistory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserCouponsHistory userCouponsHistory)
    {
        startPage();
        List<UserCouponsHistory> list = userCouponsHistoryService.selectUserCouponsHistoryList(userCouponsHistory);
        return getDataTable(list);
    }

    /**
     * 导出用户优惠券历史列表
     */
    @RequiresPermissions("mall:userCouponsHistory:export")
    @Log(title = "用户优惠券历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserCouponsHistory userCouponsHistory)
    {
        List<UserCouponsHistory> list = userCouponsHistoryService.selectUserCouponsHistoryList(userCouponsHistory);
        ExcelUtil<UserCouponsHistory> util = new ExcelUtil<UserCouponsHistory>(UserCouponsHistory.class);
        return util.exportExcel(list, "用户优惠券历史数据");
    }

    /**
     * 新增用户优惠券历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户优惠券历史
     */
    @RequiresPermissions("mall:userCouponsHistory:add")
    @Log(title = "用户优惠券历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserCouponsHistory userCouponsHistory)
    {
        return toAjax(userCouponsHistoryService.insertUserCouponsHistory(userCouponsHistory));
    }

    /**
     * 修改用户优惠券历史
     */
    @RequiresPermissions("mall:userCouponsHistory:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        UserCouponsHistory userCouponsHistory = userCouponsHistoryService.selectUserCouponsHistoryById(id);
        mmap.put("userCouponsHistory", userCouponsHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户优惠券历史
     */
    @RequiresPermissions("mall:userCouponsHistory:edit")
    @Log(title = "用户优惠券历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserCouponsHistory userCouponsHistory)
    {
        return toAjax(userCouponsHistoryService.updateUserCouponsHistory(userCouponsHistory));
    }

    /**
     * 删除用户优惠券历史
     */
    @RequiresPermissions("mall:userCouponsHistory:remove")
    @Log(title = "用户优惠券历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userCouponsHistoryService.deleteUserCouponsHistoryByIds(ids));
    }
}
